import 'package:flutter/material.dart';
import 'ContentPager.dart';

class SelfNavigator extends StatefulWidget {
  @override
  _SelfNavigatorState createState() => _SelfNavigatorState();
}

class _SelfNavigatorState extends State<SelfNavigator> {
  final Color _defaultcolor = Colors.grey;
  final Color _activecolor = Colors.blue;
  int _currentIndex = 0;

  final ContentPageController onContentPageController = ContentPageController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: ContentPager(
        onContentPageController: onContentPageController,
        onPageChangedCallbackfn: (index){
          setState(() {
            _currentIndex = index;
          });
        },
      ),

      bottomNavigationBar: BottomNavigationBar(
        currentIndex: _currentIndex,
        onTap: (int index){
          onContentPageController.jumpToPage(index);
        },
        type: BottomNavigationBarType.fixed,
        items: [
          _bottomItemcreate(title: '首页', icon: Icons.home, index: 0),
          _bottomItemcreate(title: '分享', icon: Icons.explore, index: 1),
          _bottomItemcreate(title: '免费', icon: Icons.free_breakfast, index: 2),
          _bottomItemcreate(title: '我的', icon: Icons.person, index: 3),
        ],
      ),
    );
  }

  _bottomItemcreate({String title, IconData icon, int index}){

    return BottomNavigationBarItem(
      title: Text('$title', style: TextStyle(color:_currentIndex ==index? _activecolor:_defaultcolor),),
      icon: Icon(icon, color: _defaultcolor,),
      activeIcon: Icon(icon, color: _activecolor,),
    );
  }


}

